package eleventh.StringBuffer类;

// 查找 indexOf()
public class 查找指定的内容是否存在 {
    public static void main(String[] args) {
        StringBuffer sb = new StringBuffer();
        sb.append("一去二三里");
        int index1 = sb.indexOf("二");
        int index2 = sb.indexOf("二三");
        int index3 = sb.indexOf("二三里");
        System.out.println(index1 + " " + index2 + " " + index3);   //默认是指字符串的第一个字符的位置

        //判断是否存在
        int isExist = sb.indexOf("666");
        System.out.println("isExist?:"+isExist);    // 返回 -1 代表不存在 如果存在就直接返回下标

    }
}
/*
D:\WorkSpaces\Java\jdk-21\bin\java.exe "-javaagent:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=52700:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\WorkSpaces\JavaDevelopBase_start_329\out\production\JavaDevelopBase_start_329 eleventh.StringBuffer类.查找指定的内容是否存在
2 2 2
isExist?:-1

Process finished with exit code 0

 */

